local blaze = require "blaze"
local app = require "app"
local GameObject = require "entities.interfaces.GameObject"
local Client = require "entities.interfaces.Client"
local Player = require "entities.interfaces.Player"
local game = app.game.running

local M = game.kbe.entity("BaccaratPlayer", GameObject, Client, Player)

function M:onEnterSpace()
    game.store.room.player_enter(self)
end

function M:onLeaveSpace()
    game.store.room.clear()
end

function M:onEnterWorld()
    if self.id ~= blaze.kbe.player_id() then
        -- 自己进入使用onEnterSpace事件
        game.store.room.player_enter(self)
    end
end

function M:onLeaveWorld()
    game.store.room.player_leave(self)
end

function M:onDestroy()
    if self.id == blaze.kbe.player_id() then
        game.store.room.clear()
    end
end

function M:__init__()
    GameObject.__init__(self)
    Client.__init__(self)
    Player.__init__(self)
end

function M:bet(area_id, amount)
    self:cellCall("bet", area_id, amount)
    game.store.gameplay.record_bet_history({id = area_id, amount = amount})
end

function M:set_chip(old)
    self.log.debug("on_set_chip:" .. self.chip)
    Player.set_chip(self, old)
    game.store.gameplay.set_player_chip({player = self, old = old, current = self.chip})
end

function M:on_bet(area_id, amount)
    self.log.debug(string.format("玩家下注：id=%s, area_id=%s, amount=%s", self.id, area_id, amount))
    game.store.gameplay.player_bet({player = self, area_id = area_id, amount = amount})
end

function M:on_game_init(scene)
    self.log.debug(string.format("on_game_init%s", blaze.dump(scene)))
    game.store.gameplay.init(scene)
end

return M